package p.ithorns.tools.translator.sdk.core;

import org.springframework.core.annotation.AnnotatedElementUtils;
import p.ithorns.tools.translator.annotation.Translatable;
import p.ithorns.tools.translator.sdk.utils.ReflectUtil;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;

/**
 * FieldInfo
 * TODO
 *
 * @author HtL
 * @date 2025/5/20 16:21
 * @since 1.0.0
 */
public class FieldInfo {

    /**
     * 字段
     */
    private final Field field;
    /**
     * 字典元注解
     */
    private final Annotation meta;
    /**
     * 自定义全限定名
     */
    private final String fqn;
    /**
     * 合并后的@Translatable注解
     */
    private final Translatable translatable;

    public FieldInfo(Field field, Annotation meta) {
        this.field = field;
        this.meta = meta;
        // 获取属性上的@Translatable注解，如果有衍生注解则合并相同属性
        //  * ps.这里实际缓存的是注解的代理对象
        this.translatable = AnnotatedElementUtils.getMergedAnnotation(field, Translatable.class);
        // 提前生成
        this.fqn = ReflectUtil.makeClassFieldName(field);
    }

    public Field getField() {
        return field;
    }

    public Annotation getMeta() {
        return meta;
    }

    public String getFqn() {
        return fqn;
    }


    public Translatable getTranslatable() {
        return translatable;
    }

    public boolean isDictMetaField() {
        return null != meta;
    }

}